﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LoginPanel : BasePanel
{
    private InputField _inputAccount;
    private InputField _inputPassword;
    private Button btn;
    private void Start()
    {
        btn = GetControl<Button>("LoginBtn");
        btn.onClick.AddListener(onBtnClick);
        _inputAccount=GetControl<InputField>("InputAccount");
        _inputPassword = GetControl<InputField>("InputPassword");
    }

    private void onBtnClick()
    {
      
        Client.GetInstance().ServerConnect(doSuccess,doFail);
        btn.interactable = false;
        _inputAccount.interactable = false;
        _inputPassword.interactable = false;
        
    }
    private void doFail()
    {
        Debug.Log("连接服务器失败");
        btn.interactable = true;
        _inputAccount.interactable = true;
        _inputPassword.interactable = true;
    }

    private void doSuccess()
    {
        //账号密码格式校验
        var account = _inputAccount.text;
        var password = _inputPassword.text;
        //if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
        //    return;
        //连接服务器,等待返回数据
        Cmd cmd = new LoginCmd() { Accout = account, Password = password };
        Client.GetInstance().SendCmd(cmd);

        UIManager.GetInstance().HidePanel("LoginPanel");
    }
}
